package com.aidex.web.controller.risk;

import com.aidex.risk.domain.*;
import com.aidex.system.service.WaybillService;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/risk/report")
public class ReportController {
    private static final Logger log = LoggerFactory.getLogger(ReportController.class);

    @Autowired
    private WaybillService waybillService;

    @PostMapping("/airlineCargo")
    public resultResponseT<airlineCargoResponse> airlineCargoReport(@Validated @RequestBody airlineCargoRequest info) {
        log.info("airlineCargo查询：{}", JSON.toJSONString(info));
        resultResponseT<airlineCargoResponse> result = new resultResponseT<airlineCargoResponse>();
        SimpleDateFormat nowDataFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        try {
            result=   waybillService.queryAirlineCargo(info);
            result.setStatus(200);
            result.setMessage("success");
            result.setTimestamp(date.getTime());
            return result;
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("airlineCargo查询：" , ex);
            result.setStatus(-1);
            result.setMessage("error");
            result.setTimestamp(date.getTime());
            return result;
        }
    }
    @PostMapping("/airlineCargoPiece")
    public resultResponseT<airlineCargoResponse> airlineCargoPieceReport(@Validated @RequestBody airlineCargoRequest info) {
        log.info("airlineCargo查询：{}", JSON.toJSONString(info));
        resultResponseT<airlineCargoResponse> result = new resultResponseT<airlineCargoResponse>();
        SimpleDateFormat nowDataFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        try {
            result=   waybillService.queryAirlinePieceCargo(info);
            result.setStatus(200);
            result.setMessage("success");
            result.setTimestamp(date.getTime());
            return result;
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("airlineCargo查询：" , ex);
            result.setStatus(-1);
            result.setMessage("error");
            result.setTimestamp(date.getTime());
            return result;
        }
    }
    @PostMapping("/securityCheck")
    public resultResponseT<securityCheckResponse> securityCheckReport(@Validated @RequestBody securityCheckRequest info) {
        log.info("securityCheck查询：{}", JSON.toJSONString(info));
        resultResponseT<securityCheckResponse> result = new resultResponseT<securityCheckResponse>();
        SimpleDateFormat nowDataFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        try {
            result=   waybillService.querySecurityCheck(info);
            result.setStatus(200);
            result.setMessage("success");
            result.setTimestamp(date.getTime());
            return result;
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("securityCheck查询："  , ex);
            result.setStatus(-1);
            result.setMessage("error");
            result.setTimestamp(date.getTime());
            return result;
        }
    }

    @PostMapping("/agentCredit")
    public resultResponseT<agentCreditResponse> agentCreditReport(@Validated @RequestBody agentCreditRequest info) {
        log.info("agentCredit查询：{}", JSON.toJSONString(info));
        resultResponseT<agentCreditResponse> result = new resultResponseT<agentCreditResponse>();
        SimpleDateFormat nowDataFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        try {
            result=   waybillService.queryAgentCredit(info);
            result.setStatus(200);
            result.setMessage("success");
            result.setTimestamp(date.getTime());
            return result;
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("agentCredit查询："  , ex);
            result.setStatus(-1);
            result.setMessage("error");
            result.setTimestamp(date.getTime());
            return result;
        }
    }


    @GetMapping("/queryAirline")
    public resultResponseT<String> queryAirline() {
        resultResponseT<String> result = new resultResponseT<String>();
        SimpleDateFormat nowDataFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        try {
            result=   waybillService.queryAirline();
            result.setStatus(200);
            result.setMessage("success");
            result.setTimestamp(date.getTime());
            return result;
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("queryAirline查询：" , ex);
            result.setStatus(-1);
            result.setMessage("error");
            result.setTimestamp(date.getTime());
            return result;
        }
    }

}
